import {io, Socket} from 'socket.io-client';
import {getUserInfo} from "@src/utils/userInfo.ts"
import {create} from 'zustand'
import backendUrlSet from "@src/config/backendUrlSet.ts";

const defaultSocket: Socket = io(`ws://${backendUrlSet}`, {
    auth: {
        token: getUserInfo().token,
    },
});

interface socketCreateType {
    socket: Socket;
    updateSocket: () => void;
}

export const socketCreate = create<socketCreateType>((set) => ({
    socket: defaultSocket,
    updateSocket: () => {
        set({
            socket: io(`ws://${backendUrlSet}`, {
                auth: {
                    token: getUserInfo().token,
                },
            })
        });
    }
}))

